package com.ruoyi.system.domain;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 产值对象 output
 * 
 * @author xuliang
 * @date 2024-04-05
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString
public class Output extends BaseEntity
{

    private static final long serialVersionUID = 1L;

    @ExcelIgnore
    private Long id;

    /** 项目编号 */
    @Excel(name = "项目编号")
    @ExcelProperty(value = "项目编号")
    @ColumnWidth(15)
    private String projectCode;

    /** 项目名 */
    @Excel(name = "项目")
    @ExcelProperty(value = "项目")
    @ColumnWidth(15)
    private String projectName;

    /** 含税产值 */
    @Excel(name = "累计含税产值")
    @ExcelProperty(value = "累计含税产值")
    @ColumnWidth(20)
    private BigDecimal outputWithTax;

    @Excel(name = "产值税率")
    @ExcelProperty(value = "产值税率")
    @ColumnWidth(8)
    @NumberFormat(value = "0.00%")
    private Double outputTaxRate;

    /** 除税产值 */
    @Excel(name = "累计除税产值")
    @ExcelProperty(value = "累计除税产值")
    @ColumnWidth(20)
    private BigDecimal outputNoTax;

    /** 累计应收账款 */
    @Excel(name = "累计应收账款")
    @ExcelProperty(value = "累计应收账款")
    @ColumnWidth(20)
    private BigDecimal totalReceivable;

    /** 累计已收账款 */
    @Excel(name = "累计已收账款")
    @ExcelProperty(value = "累计已收账款")
    @ColumnWidth(20)
    private BigDecimal totalReceived;

    /** 累计应收账款 */
    @Excel(name = "累计应付账款")
    @ExcelProperty(value = "累计应付账款")
    @ColumnWidth(20)
    private BigDecimal totalPayable;

    /** 累计已收账款 */
    @Excel(name = "累计已付账款")
    @ExcelProperty(value = "累计已付账款")
    @ColumnWidth(20)
    private BigDecimal totalPaid;

    /** 备注 */
    @ExcelProperty(value = "备注")
    @ColumnWidth(15)
    private String remark;

    @ExcelIgnore
    private Integer number;

    public void setProjectCode(String projectCode){
        this.projectCode = projectCode;
        calculateTax();
    }

    public void setOutputTaxRate(Double outputTaxRate) {
        this.outputTaxRate = outputTaxRate;
        calculateTax();
    }

    // 计算
    public void calculateTax() {
        if ((outputTaxRate != null && outputWithTax != null && BigDecimal.ZERO.compareTo(outputWithTax) != 0)) {
            BigDecimal divisor = BigDecimal.ONE.add(BigDecimal.valueOf(outputTaxRate));
            outputNoTax = outputWithTax.divide(divisor, 4, RoundingMode.HALF_UP);
        }
    }

}
